#!/bin/bash -e

cd $(dirname $0)/..
source ./auto/set-env-helpers

REPO_PREFIX="registry.cn-beijing.aliyuncs.com/joidevops"

# Build the image
auto/build-docker-images

# Login dockerhub
auto/auth-with-dockerhub

# Release
function push_image() {
  display_status "Release to registry"
  docker tag ${PROJECT_NAME}_${1} ${REPO_PREFIX}/${1}
  docker tag ${PROJECT_NAME}_${1} ${REPO_PREFIX}/${1}:${GIT_HASH}
  docker push ${REPO_PREFIX}/${1}
  docker push ${REPO_PREFIX}/${1}:${GIT_HASH}
  display_status "Pushed docker image ${REPO_PREFIX}/${1} with tags ${GIT_HASH}, latest"
}

push_image ${APP_NAME}
push_image ${MIGRATION_NAME}

